<template>
    <view class="container">
        <view class="list">
            <view v-for="item in page.records" class="item">
                <view class="content">{{item.content}}</view>
                <view class="time">{{item.updateTime}}</view>
            </view>
        </view>

        <uni-load-more :status="status"/>
    </view>
</template>

<script>
import {NotifyApi} from '@/api/user/NotifyApi'

export default {
    data() {
        return {
			Config: this.$Config,
			Common: this.$Common,
			Auth: this.$Auth,
			ShareUtil: this.$ShareUtil,
			State: this.$store.state,
			Dict: this.$Dict,

            page: {
                total: 0,
                size: 10,
                current: 1,
                pages: 2,
                records: []
            },
            status: 'more',
        }
    },
    onLoad() {
        this.getNotifyPage()
    },
    onPullDownRefresh() {
        this.page.current = 1
        this.page.pages = 2
        this.getNotifyPage()
    },
    onReachBottom() {
        if (this.page.current !== this.page.pages) {
            this.page.current++
            this.getNotifyPage()
        }
    },
    methods: {
        getNotifyPage() {
            let that = this
            let param = {
                pageIndex: this.page.current,
                pageSize: this.page.size
            };
            that.status = 'loading'

            NotifyApi.getNotifyPage(param).then((response) => {
                if (that.page.current === 1) {
                    that.page = response
                } else {
                    that.page.records = that.page.records.concat(response.records)
                }

                that.page.records.forEach(function (item) {
                    item.updateTime = that.Common.timeFormat(item.updateTime, 2)
                })

                if (that.page.current === that.page.pages || that.page.pages === 0) {
                    that.status = 'noMore'
                } else {
                    that.status = 'more'
                }
            })
        }
    }
}
</script>

<style scoped>
page{background: #FFF;}
.list{padding:10px;}
.list .item{border-bottom: 1px solid #EEE;padding:15px 0;}
.list .item .time{text-align: right; color:#999; margin-top:10px;}
</style>
